package com.bossien.flink.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.apache.flink.streaming.connectors.rabbitmq.common.RMQConnectionConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * @author 胡春林
 * rabbitmq  connection参数配置
 */
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Data
@Configuration
@Accessors(chain = true)
public class RabbitParamsConfig {

    //服务器IP
    @Value("${system.rabbit.host}")
    private String host;
    //服务器端口号
    @Value("${system.rabbit.port}")
    private int port;
    //服务器用户名
    @Value("${system.rabbit.username}")
    private String username;
    //服务器密码
    @Value("${system.rabbit.password}")
    private String password;
    //服务器虚拟路径
    @Value("${system.rabbit.virtualHost}")
    private String virtualHost;
    //服务器连接超时时间
    @Value("${system.rabbit.connectionTimeOut}")
    private int connectionTimeOut;
    //服务器断线自动重连
    @Value("${system.rabbit.automaticRecovery}")
    private boolean automaticRecovery;


    @Bean
    @Order(value = 1)
    public RMQConnectionConfig rmqConnectionConfig()
    {
        //开始配置rabbitmq参数(具体连接参数可详细设置)
         RMQConnectionConfig connectionConfig = new RMQConnectionConfig.Builder()
                .setHost(getHost())
                .setPort(getPort())
                .setUserName(getUsername())
                .setPassword(getPassword())
                .setConnectionTimeout(getConnectionTimeOut())
                .setAutomaticRecovery(isAutomaticRecovery())
                .setVirtualHost(getVirtualHost())
                .build();
         return connectionConfig;
    }
}